<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<link rel="stylesheet" type="text/css" href="../../../CSS/default.css" />
		<link rel="stylesheet" type="text/css" href="../../../Themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="../../../Themes/icon.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/demo.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/common.css">
	</head>

	<body style="padding: 0px;">
		<div id="toolbar" class="receipts_toolbar_style"></div>
		<form id="ff">
			<div class="easyui-tabs" id="div_tabs" style="width: 100%;height: 300px;">
				<div title="基本信息" style="overflow:hidden;width: 100%;height: 300px;">
					<div style="float: left;width: 25%;margin-top: 20px;margin-left: 10px;">
						<div style="border-style: solid;border-width: 1px;border-color: #95B8E7;border-radius: 5px;width:105px;height: 150px;margin: auto;" id="div_photo">
							<img  id="img" style="width: 100%;height: 100%;overflow: hidden;"/>
						</div>
						<div style="margin-top: 10px">
							<input id="loder_img"  class="easyui-filebox" style="width: 100%;height: 25px;" data-options="onChange:function(){getLocalImg(this)},buttonText:'本地图片'"/>
							<a href="#" id="uploader_img" class="easyui-linkbutton" style="width:100%;margin-top: 10px;">上传</a>
						</div>
					</div>
					<div style="width:70%;float: right;">
						<table id="basicInfo" class="displaytable" cellspacing="12">
							<tr>
								<td width="20%">
									<h id="star">* </h>租户姓名</td>
								<td width="30%">
									<input style="width:100%" class="easyui-textbox" id="input_NAME" name="NAME" data-options="required:true" />
								</td>

								<td width="20%">
									<h id="star">* </h>性别</td>
								<td width="30%">
									<input style="width:100%" class="easyui-combobox" id="input_GENDER" name="GENDER" data-options="required:true" />
								</td>
							</tr>
							<tr>
								<td width="20%">
									<h id="star">* </h>联系电话</td>
								<td width="30%">
									<input style="width:100%" class="easyui-textbox chechkPhone" id="input_TELEPHONE" name="TELEPHONE" data-options="required:true" />
								</td>
								<td width="20%">
									<h id="star">* </h>入场时间</td>
								<td width="30%">
									<input style="width:100%" class="easyui-datebox" id="input_ENTRANCE_TIME" name="ENTRANCE_TIME" data-options="required:true,validType:'md[\'10/11/2015\']'" />
								</td>
							</tr>
							<tr>
								<td width="20%">
									<h id="star">* </h>身份证号码</td>
								<td width="30%">
									<input style="width:100%" class="easyui-textbox checkIdcard" id="input_IDCARD" name="IDCARD" data-options="required:true" />
								</td>
								<td width="20%">
									暂住证号码</td>
								<td width="30%">
									<input style="width:100%" class="easyui-textbox" id="input_TEMPORARY_NO" name="TEMPORARY_NO"  />
								</td>
							</tr>
							<tr>
								<!--<td width="20%">
									<h id="star">* </h>营业执照类型</td>
								<td width="30%">
									<input style="width:80%" class="easyui-combobox" id="input_BUSINESS_TYPE" name="BUSINESS_TYPE" \>
									<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add'" onclick="AddBusinessLicenseType()"></a>
								</td>-->
								<td width="20%">
									<h id="star">* </h>营业执照号码</td>
								<td width="30%">
									<input style="width:100%" class="easyui-textbox" id="input_BUSINESS_NO" name="BUSINESS_NO"  />
								</td>
							</tr>
							<!--<tr>
								<td width="20%">
									<h id="star">* </h>卫生许可证</td>
								<td width="30%">
									<input style="width:100%" class="easyui-textbox" id="input_HYGIENE_NO" name="HYGIENE_NO"  />
								</td>
								<td width="20%">
									<h id="star">* </h>税务登记证号码</td>
								<td width="30%">
									<input style="width:100%" class="easyui-textbox" id="input_TAX_ID" name="TAX_ID"  />
								</td>
							</tr>-->
						</table>
					</div>
				</div>
				<div title="附加信息" style="overflow:hidden;width: 100%;height: 300px;">
					<table class="displaytable" cellpadding="12" style="padding: 30px">
						<tr>
							<td width="12%">紧急联系人</td>
							<td width="38%">
								<input class="easyui-textbox" type="text" id="input_CONTACT_NAME1" name="CONTACT_NAME1" style="width:100%" />
							</td>
							<td width="12%">联系电话</td>
							<td width="38%">
								<input class="easyui-textbox" id="input_CONTACT_TEL1" name="CONTACT_TEL1" style="width:100%" />
							</td>
						</tr>
						<tr>
							<td width="12%">户籍地址</td>
							<td width="38%">
								<input class="easyui-textbox" id="input_RESIDENCE_ADDR" name="RESIDENCE_ADDR" style="width:100%" />
							</td>
							<td width="12%">现住址</td>
							<td width="38%">
								<input class="easyui-textbox" id="input_ADDR" name="ADDR" style="width:100%" />
							</td>
						</tr>
						<tr>
							<td width="12%">从业人员</td>
							<td width="38%">
								<input class="easyui-textbox" id="input_STAFF" name="STAFF" style="width:100%" />
							</td>
							<td width="12%">经营范围</td>
							<td width="38%">
								<input class="easyui-textbox" id="input_BUSINESS_SCOPE" name="BUSINESS_SCOPE" style="width:100%" />
							</td>
						</tr>
						<tr style="display: none;">
							<td width="12%">商户类型</td>
							<td width="38%">
								<input class="easyui-textbox" id="input_TYPE" name="TYPE" style="width:100%" />
							</td>
							<td width="12%">拼音字段</td>
							<td width="38%">
								<input class="easyui-textbox" id="input_PINYINFIELDNAME" name="PINYINFIELDNAME" style="width:100%" />
							</td>
						</tr>
						<tr style="display: none;">
							<td width="12%">联系人姓名2</td>
							<td width="38%">
								<input class="easyui-textbox" id="input_CONTACT_NAME2" name="CONTACT_NAME2" style="width:100%" />
							</td>
							<td width="12%">联系人电话2</td>
							<td width="38%">
								<input class="easyui-textbox" id="input_CONTACT_TEL2" name="CONTACT_TEL2" style="width:100%" />
							</td>
						</tr>
						<tr style="display: none;">
							<td width="12%">联系人姓名3</td>
							<td width="38%">
								<input class="easyui-textbox" id="input_CONTACT_NAME3" name="CONTACT_NAME3" style="width:100%" />
							</td>
							<td width="12%">联系人电话3</td>
							<td width="38%">
								<input class="easyui-textbox" id="input_CONTACT_TEL3" name="CONTACT_TEL3" style="width:100%" />
							</td>
						</tr>
					</table>
				</div>
			</div>
			<div id="new_footer"></div>
			<div id="dlg" class="easyui-dialog" closed="true" style="width:560px;height:400px;padding:10px">
				<iframe id="ifrmEdit" height="100%" width="100%" frameborder="0" scrolling="no"></iframe>
			</div>
		</form>
		<script type="text/javascript" src="../../../JS/jquery.min.js"></script>
		<script type="text/javascript" src="../../../JS/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="../../../JS/common.js"></script>
		<script type="text/javascript" src="../../../JS/MarketShareFunction/DialogShareFunction.js"></script>
	</body>
	<script type="text/javascript">
		var content;
		var id = getID();
		var currid;
		var MaxPage;
		var MinPage;
		var photo = "";//保存头像的路径
		var currPage;
		var isVerify;
		var AddDialog;
		var receipts_type = RECEIPT_SAVE_SYMBOL;
		receipts_type += RECEIPT_ADD_SYMBOL + RECEIPT_NEXT_SYMBOL + RECEIPT_FRONT_SYMBOL + RECEIPT_DELETE_SYMBOL;
		receipts_type += RECEIPT_UNVERIFY_SYMBOL + RECEIPT_VERIFY_SYMBOL + RECEIPT_PRINT_SYMBOL ;
		content = AddReceiptsToolBar(receipts_type, "");
		$("#toolbar").append(content);
		addDialogFooter($("#new_footer"));
		getPageMaxAndMin();
		
//		$("#input_BUSINESS_TYPE").combobox({
//			panelHeight: 'auto',
//			valueField: 'NAME',
//			textField: 'NAME',
//			url:RemoteLinkAddress+"/businesslicensetype/listall.do",
//		});
		
		function getLocalImg(Pobj){
			var img = $(Pobj).filebox("getValue");
			_file = $(Pobj).context.ownerDocument.activeElement.files[0];
			$("#img").attr("src",getImgLocal(_file));
		}
		
		//获取本地图片的地址
		function getImgLocal(file){
			var _url;
			if(window.createObjectURL != undefined){
				_url = window.createObjectURL(file);
			}else if(window.URL != undefined){
				_url = window.URL.createObjectURL(file);
			}else if(window.webkitURL != undefined){
				_url = window.webkitURL.createObjectURL(file);
			}
			return _url;
			
		}
		$("#uploader_img").click(function(){
			processFileUpload();
		});
		function processFileUpload() {
			if(_file == null || _file == undefined){
				$.messager.alert("警告","无效的文件");
				return ;
			}
			var oMyForm = new FormData();
			oMyForm.append("file", _file);
			$.ajax({
				dataType: 'JSON',
				url: RemoteLinkAddress + "/pic/save.do",
				data: oMyForm,
				type: "POST",
				enctype: 'multipart/form-data',
				processData: false,
				contentType: false,
				success: function(result) {
					if(result.msg != ""){
						photo = result.msg;
					}
				},
				error: function(result) {
					$.messager.alert("消息", "上传失败！");
				}
			});
		}
		$(document).ready(function(){
			if(id != AddFlag) {
				currid = id;
				loadRemoteData();
			} else {
				currid = AddFlag;
			}
        });
		initCombobox();
		
		function loadRemoteData()
		{
			var _url = RemoteLinkAddress + '/market/tenant/findbyid.do?ID=' + currid;
			getRemoteData(_url);
		}

		function frontpage() {
			if(currid == AddFlag) {
				currid = currPage;
			}
			if(currid <= MinPage) {
				$.messager.alert("消息", "没有上张");
				return;
			}
			var _url = RemoteLinkAddress + '/market/tenant/pre.do?TYPE=0&ID=' + currid;
			getRemoteData(_url);
		}

		function nextpage() {
			if(currid == AddFlag) {
				currid = currPage;
			}
			if(currid >= MaxPage) {
				$.messager.alert("消息", "没有下张");
				return;
			}
			var _url = RemoteLinkAddress + '/market/tenant/next.do?TYPE=0&ID=' + currid;
			getRemoteData(_url);
		}

		function newdata() {
			$("#verifydisplay").empty();//去掉审核或者未审核的图片
			isVerify = 0;//将状态改为未审核
			currid = AddFlag;
			resetData();
		}

		function save() {
			var tip;
			var isValid = $("#ff").form('validate');
			if(!isValid) {
				$.messager.alert("警告", "有必填项没有填写");
				return;
			}
			tip = checkDataFormat();
			if(tip != "验证成功") {
				$.messager.alert("错误", tip);
				return;
			}
			var _url;
			if(currid == AddFlag) {
				_url = RemoteLinkAddress + "/market/tenant/save.do";
			} else {
				if(isVerify == 1) {
					$.messager.alert("警告", "表单已审核不能修改!");
					return;
				}
				_url = RemoteLinkAddress + "/market/tenant/update.do";
			}
			saveData(_url);
		}

		function deletedata() {
			if(isVerify == 1) {
				$.messager.alert("警告", "订单已审核，无法删除");
				return;
			}
			if(currid == AddFlag){
				$.messager.alert("警告","该订单为新增订单，无法删除");
				return;
			}
			$.messager.confirm("确认", "是否删除", function(r) {
				if(r) {
					$.post(RemoteLinkAddress + "/market/tenant/delete.do", {
						"ID": currid,
					}, function(result) {
						if(result.msg == "success") {
							$.messager.alert({
								title: '成功',
								msg: '删除成功!'
							});
							nextpage();
							reloadList();
						} else {
							$.messager.alert({
								title: 'Error',
								msg: result.msg
							});
						}
					}, 'json');
				}
			});
		}

		
		function verifydata() {
			if(isVerify == 1) {
				$.messager.alert("警告", "订单已审核，无须再审");
				return;
			}
			$.messager.confirm("确认", "是否审核", function(r) {
				if(r) {
					$.post(RemoteLinkAddress + "/market/tenant/verify.do", {
						"ID": currid,
					}, function(result) {
						if(result.msg == "success") {
							$.messager.alert({
								title: '成功',
								msg: '审核成功!'
							});
							verifyStatus_Market(1, true);
							isVerify = 1;
							reloadList();
						} else {
							$.messager.alert({
								title: 'Error',
								msg: result.msg
							});
						}
					}, 'json');
				}
			});
		}

		function unverifydata() {
			if(isVerify == 0) {
				$.messager.alert("警告", "订单已弃审，无须再审");
				return;
			}
			$.messager.confirm('Confirm', '是否弃审', function(r) {
				if(r) {
					$.post(RemoteLinkAddress + "/market/tenant/unverify.do", {
							"ID": currid,
						},
						function(result) {
							if(result.msg == "success") {
								$.messager.alert({
									title: '成功',
									msg: '放弃审核成功!'
								});
								verifyStatus_Market(0, true);
								isVerify = 0;
								reloadList();
							} else {
								$.messager.alert({
									title: 'Error',
									msg: result.msg
								});
							}
						},
						'json');
				}
			});
		}

		function print() {
			if(isVerify == 0) {
				$.messager.alert("警告", "订单未审核，不能打印");
				return;
			}
			if(currid == AddFlag) {
				$.messager.alert("警告", "当前为新增页面，不能打印");
				return;
			}
			window.open("BusinessInformationPrint.html?id=" + currid);
		}

		function getPageMaxAndMin() {
			var _url = RemoteLinkAddress + "/market/tenant/getmaxminid.do";
			$.ajax({
				type: "get",
				url: _url,
				dataType: "json",
				success: function(result) {
					if(result != null) {
						MaxPage = result.MAXID;
						MinPage = result.MINID;
						currPage = MinPage + 1;
					}
				},
				error: function(xhr, status, error) {
					$.messager.alert("错误", "请求失败!");
				}
			});
		}

		function getRemoteData(_url) {
			$.ajax({
				type: "get",
				url: _url,
				dataType: "json",
				success: function(result) {
					if(result != null) {
						if(result.msg === "nextnull") {
							$.messager.alert("消息", "没有下张");
							return;
						}
						if(result.msg === "prenull") {
							$.messager.alert("消息", "没有上张");
							return;
						}
						if(result.PHOTO == undefined){
							result.PHOTO = "";
						}
						photo = RemoteLinkAddress +"/"+ result.PHOTO;
						isVerify = result.ISVERIFY;
						currid = result.ID;
						currPage = result.ID;
						getDialogData(result);
						verifyStatus_Market(isVerify, true);
						$("#img").attr("src",photo);
					}
				}
			});
		}

		function saveData(_url) {
			var _data = submitDialogData();
			_data.PHOTO = photo;
			if(currid == AddFlag) {
				_data.TYPE = "0";
			}
			if(currid != AddFlag) {
				_data.ID = currid;
			}
			$.ajax({
				type: "post",
				url: _url,
				dataType: "JSON",
				data: _data,
				success: function(result) {
					if(result.msg.search("success") > -1) {
						var parentLocation;
						parentLocation = searchParent("BusinessInformationList.html");
						parentLocation.dialogClose();
						$.messager.alert('提示信息', '保存成功!');
						reloadList();
					} else {
						$.messager.alert("提示信息", result.msg);
					}
				},
				error: function(result) {
					$.messager.alert('提示信息', '保存失败');
				}
			});
		}

//		function AddBusinessLicenseType() {
//			var pLocation = "../DictData/DictDataAdd.html?id=businesslicensetype";
//			$("#ifrmEdit").attr("src", pLocation);
//			constructcomboDialog($("#dlg"), "添加营业执照类型", $("#input_BUSINESS_TYPE"));
//			AddDialog.dialog('open');
//		}
		
		//刷新list页面
		function reloadList(){
			var parentLocation;
			parentLocation = searchParent("BusinessInformationList.html");
			data = parentLocation.redodata();
		}
		Tabs_Hover();
	</script>

</html>